import {serviceSimple} from '@/api/index'

export default {
    namespaced:true,
	actions: {
        //获取商品详情信息
        async getGoodDetail({commit},skuid){
            const res=await serviceSimple({url:`/item/${skuid}`})
       
            if(res.data.code==200){
                commit('GETGOODDETAIL',res.data.data)
            }
        },

        async addGoodToCart({commit},{skuid,skuNum}){
            let res=await serviceSimple({url:`/cart/addToCart/${skuid}/${skuNum}`,method:'post'})
           
            if(res.data.code==200) return 200
            else return Promise.reject('失败')
        }
    },
	mutations: {
        GETGOODDETAIL(state,GoodDetailData){
            state.GoodDetailData=GoodDetailData
        }
    },
	state: {
        GoodDetailData:{}
    },
    getters:{
        categoryView(state){
           return state.GoodDetailData.categoryView||{}
        },
        skuInfo(state){
            return state.GoodDetailData.skuInfo||{}
        },
        price(state){
            return state.GoodDetailData.price||{}
        },
        spuSaleAttrList(state){
            return state.GoodDetailData.spuSaleAttrList||[]
        }

    }
};
